package com.dongdongshop.controller;

import com.dongdongshop.pojo.TbAreas;
import com.dongdongshop.pojo.TbCities;
import com.dongdongshop.pojo.TbProvinces;
import com.dongdongshop.service.ProvincesService;
import com.dongdongsop.data.AjaxResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("provinces")
public class ProvincesController {

    @DubboReference
    private ProvincesService provincesService;

    //查询省
    @RequestMapping("getProvince")
    @ResponseBody
    public AjaxResult getProvince(){
        try {
            List<TbProvinces> provincesList = provincesService.getProvince();
            return AjaxResult.OK().setData(provincesList);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }

    //查询市
    @RequestMapping("getCity")
    @ResponseBody
    public AjaxResult getCity(String id){
        try {
            List<TbCities> citiesList = provincesService.getCity(id);
            return AjaxResult.OK().setData(citiesList);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }

    //查询区
    @RequestMapping("getDistrict")
    @ResponseBody
    public AjaxResult getDistrict(String id){
        try {
            List<TbAreas> areasList = provincesService.getDistrict(id);
            return AjaxResult.OK().setData(areasList);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }
}
